# @Author: 唐奇才
# @Time: 2021/5/25 17:39
# @File: index.py
# @Software: PyCharm

import os
import numpy as np
from PIL import Image


class MoveImage:
    def __init__(self, path_head, pc, phone):
        self.path_head = path_head + "/"
        self.pc = pc + "/"
        self.phone = phone + "/"

    def is_phone_img(self, path):
        img = Image.open(path)
        # 行数据和列（特征）
        info = np.array(img).shape
        h, w = info[0], info[1]
        if h >= w:
            return True
        else:
            return False

    def run(self):
        i = 0
        imgs = os.listdir(self.path_head)
        for img in imgs:
            i  += 1
            src_path = self.path_head + img
            if self.is_phone_img(src_path):
                os.rename(src_path, self.phone + img)
            else:
                os.rename(src_path, self.pc + img)
            print("第{}张图片移动成功".format(i))
        print("所有图片移动成功！^_^")




def main():
    mi = MoveImage("./images/img/",
              "./images/PC/",
              "./images/phone"
              )
    mi.run()


if __name__ == '__main__':
    main()